﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Functions - Sum of Even Numbers</title>
	<link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>							  

	<label for="tb-numbers">Enter numbers, separated by comma ",": </label>
	<input id="tb-numbers" type="text" class="js-console-input" />
	<a href="#" class="js-console-btn" onclick="onSumEvenNumbers()">Sum even numbers</a>
	<div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>

		function onSumEvenNumbers() {
			var numbers = jsConsole.readNumbersArray("#tb-numbers", ",");
			jsConsole.writeLine(sum(numbers));
		}

		function sum(numbers) {
			var sum = 0;
			for (var i in numbers) {
				if (numbers[i] % 2 == 0) {
					sum += numbers[i];
				}
			}
			return sum;
		}
	</script>

</body>
</html>
